﻿using AppSocketModel;
using AppSocketService.Vehicle;
using BCGPSCommon;
using BCGPSRESTful.WebApiConfig;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;

namespace BCGPSRESTful.Controllers.Page.Vehicle
{
    /// <summary>
    /// 账户车辆信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "CompanyPage")]
    [Route("api/[controller]")]
    [ApiController]
    public class VehicleController : PageBaseController
    {
        private IVehicleService vehicleService;

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public VehicleController(IVehicleService vehicleService)
        {
            this.vehicleService = vehicleService;
        }
        #endregion

        #region 给账户添加新车信息
        /// <summary>
        /// 给账户添加新车信息
        /// </summary>
        /// <returns></returns> 
        [HttpPost("[action]")]
        [ProducesResponseType(typeof(VehicleDto), 200)]
        public ActionResult<VehicleDto> AddNew(VehicleRequestDto vehicleDto)
        {
            return vehicleService.AddNew(vehicleDto);
        }
        #endregion

        #region 修改账户车辆信息 根据 imei
        /// <summary>
        /// 修改账户车辆信息 根据 imei 
        /// </summary>
        /// <param name="vehicleDto"></param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(VehicleDto), 200)]
        public ActionResult<VehicleDto> Update(VehicleDto vehicleDto)
        {
            return vehicleService.Update(vehicleDto);
        }
        #endregion

        #region 删除账户车辆信息
        /// <summary>
        /// 删除账户车辆信息
        /// </summary>
        /// <param name="imei">imei</param> 
        /// <returns></returns>
        [HttpDelete("[action]")]
        [ProducesResponseType(typeof(int), 200)]
        public ActionResult<int> Delete(string imei)
        {
            return vehicleService.Delete(imei);
        }
        #endregion

        #region 获取指定账户下全部车辆 不包含子账户
        /// <summary>
        /// 获取指定账户下全部车辆 不包含子账户
        /// </summary>
        /// <param name="account_id">账户Id</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleDto>), 200)]
        public ActionResult<List<VehicleDto>> QueryVehicleList(string account_id)
        {
            return vehicleService.GetVehicleList(account_id);
        }
        #endregion

        #region 获取指定账户下全部车辆 不包含子账户 -- 分页 
        /// <summary>
        /// 获取指定账户下全部车辆 不包含子账户 -- 分页 
        /// </summary>
        /// <param name="account_id">账户Id</param>
        /// <param name="index">页码</param>
        /// <param name="size">记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<VehicleDto>), 200)]
        public ActionResult<PageableList<VehicleDto>> QueryVehicleListPage(string account_id, int? index=0, int? size=20)
        {
            return vehicleService.GetVehicleList(account_id,index.Value,size.Value);
        }
        #endregion

        #region 获取指定账户包括子账户下全部车辆 
        /// <summary>
        /// 获取指定账户包括子账户下全部车辆
        /// </summary>
        /// <param name="account_id">账户Id</param>
        /// <returns></returns> 
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleDto>), 200)]
        public ActionResult<List<VehicleDto>> QueryVehicleListAll(string account_id)
        {
            return vehicleService.GetVehicleListAll(account_id);
        }
        #endregion

        #region 获取指定车辆信息和定位信息
        /// <summary>
        /// 获取指定车辆信息和定位信息
        /// </summary>
        /// <param name="imei"></param> 
        /// <param name="gps_map_type">地图种类</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(VehicleLocationDto), 200)]
        public ActionResult<VehicleLocationDto> QueryVehicleLocation(string imei, GpsMapType? gps_map_type = GpsMapType.GDMAP)
        {
            return vehicleService.GetVehicleLocation(imei, gps_map_type.Value);
        }
        #endregion

        #region 获取指定账户下全部车辆和定位信息  不包含子账户
        /// <summary>
        /// 获取指定账户下全部车辆和定位信息  不包含子账户
        /// </summary>
        /// <param name="account_id">账户Id</param>
        /// <param name="gps_map_type">地图种类</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleLocationDto>), 200)]
        public ActionResult<List<VehicleLocationDto>> QueryVehicleLocationList(string account_id, GpsMapType? gps_map_type = GpsMapType.GDMAP)
        {
            return vehicleService.GetVehicleLocationList(account_id, gps_map_type.Value);
        }
        #endregion

        #region 获取指定账户包括子账户下全部车辆信息和定位信息 
        /// <summary>
        /// 获取指定账户包括子账户下全部车辆信息和定位信息
        /// </summary>
        /// <param name="account_id">账户Id</param>
        /// <param name="gps_map_type">地图种类</param>
        /// <returns></returns> 
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<VehicleLocationDto>), 200)]
        public ActionResult<List<VehicleLocationDto>> QueryVehicleLocationListAll(string account_id, GpsMapType? gps_map_type = GpsMapType.GDMAP)
        {
            return vehicleService.GetVehicleLocationListAll(account_id, gps_map_type.Value);
        }
        #endregion

        #region 获取指定账户下车辆的设备信息(不包括子账户) -- 分页 
        /// <summary>
        /// 获取指定账户下车辆的设备信息(不包括子账户) -- 分页
        /// </summary>
        /// <param name="account_id">账户Id</param> 
        /// <param name="desc">倒序</param>
        /// <param name="index">页码</param>
        /// <param name="size">记录数</param>
        /// <returns></returns> 
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<DeviceDto>), 200)]
        public ActionResult<PageableList<DeviceDto>> QueryDeviceListPage(string account_id,bool? desc = false  , int? index = 0, int? size = 20)
        {
            return vehicleService.GetDeviceList(account_id, desc.Value,index.Value,size.Value);
        }
        #endregion

        #region 设置车辆归属账户
        /// <summary>
        /// 设置车辆归属账户
        /// </summary>
        /// <param name="imei">imei</param>
        /// <param name="account_id">账户Id</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(VehicleDto),200)]
        public ActionResult<VehicleDto> SetVehicleAccount(string imei, string account_id)
        {
            return vehicleService.SetVehicleAccount(imei, account_id);
        }
        #endregion
    }
}